import numpy as np
import cv2

"""
像元尺寸: 4.0*4.0μm
相机分辨率:1280*1024
焦距: 6mm
"""

# 相机参数
z = 2  # 物距为2m
f = 0.006  # 焦距, 为6mm
l = 0.000004  # 像元大小，为4μm
k = 0.000004
cx = 640  # 1280
cy = 512  # 1024
a = f / k
b = f / l

# 构造相机内参矩阵
m = np.zeros((3, 4))
m[0, 0] = a
m[1, 1] = b
m[0, 2] = cx
m[1, 2] = cy
m[2, 2] = 1

# 实际坐标
position = np.array([0.25, 0.25, 2, 1]).T
position_f = np.dot(m, position)

# 缩小z倍
x = int(position_f[0] / z)
y = int(position_f[1] / z)
print("The picture's size is %.1f, %.1f in the sensor " % (x, y))

# 显示成像
img_blue = np.zeros([x, y, 3], np.uint8)
img_blue[:, :, 0] = 255
cv2.imshow('blue', img_blue)
cv2.imwrite('image.jpg', img_blue)
cv2.waitKey()
cv2.destroyAllWindows()


